﻿using ctolua.Models.Class;

namespace ctolua.Models
{
    public class MPoint
    {
        /// <summary>
        /// 点对象
        /// </summary>
        public Point point { get; set; }
        /// <summary>
        /// 点坐标
        /// </summary>
        public vec3 v3 = new vec3();

        /// <summary>
        /// x
        /// </summary>
        public double x
        {
            get
            {
                this.v3.x = global_api.get_fixed_coord_index(this.point, 0).@float();
                return this.v3.x;
            }

        }
        /// <summary>
        /// y
        /// </summary>
        public double y
        {
            get
            {
                this.v3.y = global_api.get_fixed_coord_index(this.point, 2).@float();
                return this.v3.y;
            }

        }
        /// <summary>
        /// z
        /// </summary>
        public double z
        {
            get
            {
                this.v3.z = global_api.get_fixed_coord_index(this.point, 1).@float();
                return this.v3.z;
            }

        }

        /// <summary>
        /// 坐标值转化为FVector3
        /// </summary>
        /// <param name="v">坐标对象</param>
        public MPoint(vec3 v)
        {
            this.v3 = v;
            this.point = global_api.coord_to_point(py.Fix32(v.x), py.Fix32(v.y), py.Fix32(v.z));

        }

        /// <summary>
        /// 坐标值转化为FVector3
        /// </summary>
        /// <param name="v">坐标对象</param>
        public MPoint(double? x, double? y, double? z)
        {
           
            this.point = global_api.coord_to_point(py.Fix32(x), py.Fix32(y), py.Fix32(z));

        }
        /// <summary>
        /// 通过资源id返回点
        /// </summary>
        /// <param name="res_id">资源id</param>
        public MPoint(int? res_id)
        {
            this.point = game_api.get_point_by_res_id(res_id);

        }
        /// <summary>
        /// 通过实体获得
        /// </summary>
        /// <param name="p"></param>
        public MPoint(Point p)
        {
            this.point = p;
        }

        public static MPoint obj(Point p)
        {
            return new MPoint(p);
        }

        /// <summary>
        /// 点对象是否存在
        /// </summary>
        /// <returns></returns>
        public bool? is_null() => game_api.point_is_exist(this.point);

        /// <summary>
        /// 设置点碰撞
        /// </summary>
        /// <param name="is_add ">  添加/去除   </param>
        /// <param name="ground_channel ">  地面碰撞   </param>
        /// <param name="air_channel ">  飞行碰撞   </param>
        public void set_point_collision(bool? is_add, bool? ground_channel, bool? air_channel)
        {
            game_api.set_point_collision(this.point, is_add, ground_channel, air_channel);
        }

        /// <summary>
        /// 判断点是否在正方形内
        /// </summary>
        /// <param name="center ">  中心点   </param>
        /// <param name="width ">  正方形边长   </param>
        /// <returns>点是否在正方形中</returns>
        public bool? judge_point_in_rec(MPoint center, Fix32 width)
        {
            return game_api.judge_point_in_rec(this.point, center.point, width);
        }

        /// <summary>
        /// 获取当前点的碰撞类型
        /// </summary>
        /// <returns>碰撞类型</returns>
        public int? get_point_ground_collision()
        {
            return game_api.get_point_ground_collision(this.point);
        }

        /// <summary>
        /// 获取当前点的视野隔断类型
        /// </summary>
        /// <returns>隔断类型</returns>
        public int? get_point_view_block_type()
        {
            return game_api.get_point_view_block_type(this.point);
        }

        /// <summary>
        /// 开关目标点的草丛
        /// </summary>
        /// <param name="enable ">  开关   </param>
        /// <param name="point ">  点   </param>
        public void set_grass_enable_by_pos(bool? enable)
        {
            game_api.set_grass_enable_by_pos(enable, this.point);
        }

        /// <summary>
        /// 修改某点的地形纹理
        /// </summary>
        /// <param name="texture_type ">  纹理类型   </param>
        /// <param name="radius ">  范围   </param>
        /// <param name="area_shape ">  区域类型   </param>
        public void modify_point_texture(int? texture_type, int? radius, int? area_shape)
        {
            game_api.modify_point_texture(this.point, texture_type, radius, area_shape);
        }

        /// <summary>
        /// 检测点是否和单位碰撞
        /// </summary>
        /// <param name="point ">  点   </param>
        /// <param name="radius ">  范围   </param>
        /// <returns>是否碰撞</returns>
        public bool? unit_can_collide_with_point(Unit unit, double? radius)
        {
            return game_api.unit_can_collide_with_point(unit, this.point, radius);
        }

        /// <summary>
        /// 检查点到点是否联通
        /// </summary>
        /// <param name="unit ">  寻路单位   </param>
        /// <param name="pointb ">  终点   </param>
        /// <returns>是否联通</returns>
        public bool? can_point_reach_point(Unit unit, Point pointb)
        {
            return game_api.can_point_reach_point(unit, this.point, pointb);
        }

        /// <summary>
        /// 获取不同形状范围内的可破坏物列表
        /// </summary>
        /// <param name="point"> 区域对象 </param>
        /// <param name="shape"> 形状 </param>
        /// <param name="sort_type"> 筛选规则 </param>
        /// <returns>可破坏物列表</returns>
        public dynamic get_all_dest_in_shapes(Shape shape, int? sort_type)
        {
            return game_api.get_all_dest_in_shapes(this.point,  shape,  sort_type);
        }

        /// <summary>
        /// 获取点范围内的可破坏物列表
        /// </summary>
        /// <param name="rng ">  半径   </param>
        /// <returns>可破坏物列表</returns>
        public dynamic get_all_dest_in_point_rng(double? rng)
        {
            return game_api.get_all_dest_in_point_rng(this.point, rng);
        }
        /// <summary>
        /// 点向方向偏移
        /// </summary>
        /// <param name="angle"> 方向角度 </param>
        /// <param name="dis"> 偏移距离 </param>
        /// <returns>返回值</returns>
        public MPoint get_point_offset_vector( double angle, double dis)
        {
            return new MPoint(global_api.get_point_offset_vector(this.point, py.Fix32(angle), py.Fix32(dis))) ;
        }
    }
}
